//
//  BuKeInformationDetailVC.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/26.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "BuKeInformationDetailVC.h"

#import "SYPlayerViewController.h"
#import "SYPPTViewController.h"
//=======
//#import "BuKeXiangQIngModel.h"
//>>>>>>> .r1510

@interface BuKeInformationDetailVC ()<ZXFDCCVNavSelectedDelegate>{
    int numberOfCellTop;
}
//@property (nonatomic, strong) BuKeXiangQIngModel *mainModel;
@property (strong, nonatomic) SYBuKeDetailsModel *detailsModel;

@property (strong, nonatomic) SYNoLabel *noLab;


@end

@implementation BuKeInformationDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
- (void)initSubView{
    numberOfCellTop = 0;
    self.view.backgroundColor = MAINBACKCOLOR;
    [self.view addSubview:self.navView];
    [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    
    [self.view addSubview:self.tableList];
    [_tableList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0).offset(0);
        make.top.equalTo(self->_navView.mas_bottom);
        make.bottom.equalTo(@0);
    }];
    
    _noLab = [[SYNoLabel alloc] initWithNameStr:@"" contView:self.view];
    
    [_noLab mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(44);
        make.right.left.bottom.equalTo(self.view);
    }];
    
}
- (void)layout{
    
}
- (BKIDetailVCNavView *)navView{
    if (!_navView) {
        BKIDetailVCNavView *topView = [[BKIDetailVCNavView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
        topView.titleLabe.text = @"补课详情";
        topView.delegate = self;
        [topView initOption];
        _navView = topView;
    }
    return _navView;
}

- (void)requestDataListTutorApplyId:(NSString *)applyId isOnLine:(NSString *)isOnLine {

    __weak typeof(self) weakSelf = self;
    self.tableList.hidden = YES;
    [MBProgressHUD mj_showLoading];

    [SYRequestAPI fd_requestLessonTutorLessonLineDetailsTutorAppleyId:applyId isOnLine:isOnLine success:^(SYBuKeDetailsModel *listArr) {

        [MBProgressHUD mj_hideHUD];
        if (listArr.dataResource.dataResourceFile.count == 0) {
            weakSelf.noLab.hidden = NO;
            weakSelf.tableList.hidden = YES;
        } else {
            weakSelf.tableList.hidden = NO;
            weakSelf.noLab.hidden = YES;
        }
        weakSelf.detailsModel = listArr;
        [self.tableList reloadData];

    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self.view];
        [MBProgressHUD zr_showError:error.domain];
    }];
}


- (void)backClick{
    [UIView animateWithDuration:0.5 animations:^{
        self.view.frame= CGRectMake(self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
    } completion:^(BOOL finished) {
        [self.view removeFromSuperview];
        self.view = nil;
    }];
}
- (UITableView *)tableList{
    if (!_tableList) {
        UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 144, self.view.frame.size.width, APP_HEIGHT-84) style:UITableViewStylePlain];
        tableView.delegate  =self;
        tableView.dataSource = self;
        tableView.backgroundColor = [UIColor whiteColor];
        [tableView registerClass:[BuKeXiangQingFileCell class] forCellReuseIdentifier:@"BuKeXiangQingFileCell"];
        [tableView registerClass:[BuKeInforBanJiDetailCell class] forCellReuseIdentifier:@"BuKeInforBanJiDetailCell"];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableList = tableView;
    }
    return _tableList;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    if (section == 0) {
        return self.detailsModel.dataResource.dataResourceFile.count;
    } else {
        return self.detailsModel.dataStudents.count;
    }
    

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 100;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        SYDataResourceFileModel *resourceModel = self.detailsModel.dataResource.dataResourceFile[indexPath.row];
        BuKeXiangQingFileCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BuKeXiangQingFileCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[BuKeXiangQingFileCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BuKeXiangQingFileCell"];
        }

        cell.titleLabel.text = resourceModel.name;
        cell.detailLabel.text = SYStringWithPickFormat(resourceModel.size, @"MB");
        cell.dateLabel.text = resourceModel.duration;
        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:resourceModel.icon] placeholderImage:[UIImage imageNamed:@""]];
//        cell.selectionStyle = UITableViewCellSelectionStyleNone;
//=======
//        DataResourceFileModel *model = _mainModel.dataResourceFileArray[indexPath.row];
//        cell.titleLabel.text = model.name;
//        [cell.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.icon]];
//        cell.detailLabel.text = model.size;
//        cell.dateLabel.text = model.level;
//>>>>>>> .r1510
        return cell;
    }else{
        BuKeInforBanJiDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BuKeInforBanJiDetailCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[BuKeInforBanJiDetailCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BuKeInforBanJiDetailCell"];
        }
        cell.xueHaoLabel.text  =@"S21576";
        cell.xingMingLabel.text = @"李晓彤_试听";
        cell.genderLabel.text = @"女";
        cell.suoZaiBanJiLabel.text = @"单茹 18 慧阅读1-2-D 三晚+六A";
        return cell;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        SYDataResourceFileModel *resourceModel = self.detailsModel.dataResource.dataResourceFile[indexPath.row];
        
        if ([resourceModel.suffix containsString:@"mp4"]) {
            SYPlayerViewController *playerVC = [[SYPlayerViewController alloc] init];
            playerVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
            playerVC.urlStr = SYStringWithPickFormat(kSYWebViewUrlDefent, resourceModel.path);
            [self presentViewController:playerVC animated:YES completion:nil];
        } else {
            SYPPTViewController *wordVC = [[SYPPTViewController alloc] init];
            wordVC.urlStr = SYStringWithPickFormat(kSYWebViewUrlDefent, resourceModel.path);;
            wordVC.nameStr = resourceModel.name;
            wordVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
            [self presentViewController:wordVC animated:YES completion:nil];
        }
        
    }
   // NSLog(@"点击了cell");
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (!_buKeXiangQingFileHeaderView){
        _buKeXiangQingFileHeaderView = [[BuKeXiangQingWenJianHeaderView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
        //__weak typeof(self)weakeSelf = self;
        _buKeXiangQingFileHeaderView.block = ^(BOOL selected) {
            
           // [weakeSelf.tableList reloadData];
        };
      //  _buKeXiangQingFileHeaderView.detailLabel.text = [NSString stringWithFormat:@"文件：%@  大小：%@",_mainModel.files,_mainModel.size];
    }
    if (!_buKeXiangQingBanJiHeaderView) {
        _buKeXiangQingBanJiHeaderView =[[BuKeXiangQingBanJiDetailHeaderView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 100)];
    }
    if (section == 0) {
//        _buKeXiangQingFileHeaderView.nameLabel.text = @"补课资源";
        _buKeXiangQingFileHeaderView.titleLabel.text =@"补课资源"; //self.detailsModel.dataResource;
        _buKeXiangQingFileHeaderView.detailLabel.text = [NSString stringWithFormat:@"文件：%ld  大小：%@ MB",self.detailsModel.dataResource.dataResourceFile.count,self.detailsModel.dataResource.size];
        return _buKeXiangQingFileHeaderView;
    }else{
        _buKeXiangQingBanJiHeaderView.nameLabel.text = @"班级学生";
        return _buKeXiangQingBanJiHeaderView;
    }
    
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *mainView = [[UIView alloc]init];
    mainView.frame = CGRectMake(0, 0, self.view.frame.size.width, 0);
    return mainView;
}
- (void)dealloc{
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
